﻿#ifndef APF_H
#define APF_H

#include <iostream>
#include <vector>
#include <cmath>
#include <limits>

class APF {
public:
    struct Node {
        int x, y;
        double potential;
        Node* parent;
    };

    APF();  // 空初始化构造函数
    ~APF();

    void InitializeMap(int width, int height);  // 初始化栅格地图
    void SetStartEnd(Node start, Node end);
    void AddObstacle(int x, int y);
    std::vector<Node> PlanPath();
    void PrintPotentialField();
    void SetMaxIterations(int iterations);

private:
    std::vector<std::vector<Node>> map;
    std::vector<std::pair<int, int>> obstacles;
    Node startNode, endNode;
    int width, height;
    double k_att, k_rep, eta, rho0;
    int max_iterations;

    double AttractivePotential(int x, int y);
    double RepulsivePotential(int x, int y);
    void ComputePotentialField();
    std::vector<Node> FindPath();
    Node FindNextNode(Node node);
};

#endif // APF_H
